import React, { useState } from 'react'
import { Button, Checkbox, Form, Input, Modal } from 'antd';
import axios from '../../api/request'
import { useNavigate } from 'react-router-dom';
type FieldType = {
  account?: string;
  password?: string;
  remember?: string;
};
function Index() {
  const navigate = useNavigate();
  const onFinish: FormProps<FieldType>['onFinish'] = async (values) => {
    const res = await axios.post('/login', values)
    localStorage.setItem('token', res.data.token)
    alert('登录成功')
    navigate('/home')
  };
  return (
    <div>
      <Form
        name="basic"
        labelCol={{ span: 8 }}
        wrapperCol={{ span: 16 }}
        style={{ maxWidth: 600 }}
        initialValues={{ remember: true }}
        onFinish={onFinish}
        autoComplete="off"
      >
        <Form.Item<FieldType>
          label="用户名"
          name="account"
          rules={[{ required: true, message: '请输入账号!' }]}
        >
          <Input />
        </Form.Item>

        <Form.Item<FieldType>
          label="密码"
          name="password"
          rules={[{ required: true, message: '请输入密码!' }]}
        >
          <Input.Password />
        </Form.Item>

        <Form.Item label={null}>
          <Button type="primary" htmlType="submit">
            登录
          </Button>
        </Form.Item>
      </Form>
    </div>
  )
}

export default Index
